
package Model;

import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;

/**
 *
 * @author pol
 */
public class DriverModel extends AbstractTableModel {

    public DriverModel(Driver[] d, String[] h) {
        driverList = d;
        header = h;
    }

    /**
     * Returns the number of rows in the model. A JTable uses this method to
     * determine how many rows it should display. This method should be quick,
     * as it is called frequently during rendering.
     *
     * @return the number of rows in the model
     * @see #getColumnCount
     */
    @Override
    public int getRowCount() {
        return driverList.length;
    }

    /**
     * Returns the number of columns in the model. A JTable uses this method to
     * determine how many columns it should create and display by default.
     *
     * @return the number of columns in the model
     * @see #getRowCount
     */
    @Override
    public int getColumnCount() {
        return header.length;
    }

    /**
     * Return the value for the cell at columnIndex and rowIndex
     *
     * @param rowIndex the row whose value is to be queried
     * @param columnIndex the column whose value is to be queried
     * @return the value Object at the specified cell
     */
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                return driverList[rowIndex].getName();
            case 1:
                return driverList[rowIndex].getClassDriver();
            case 2:
                return driverList[rowIndex].getExperience();
            case 3:
                return driverList[rowIndex].getSalary();
            default:
                throw new RuntimeException("No such clolumn");
        }
    }

    public String getColumnName(int index) {
        return header[index];
    }

    /**
     * Return list of drivers
     *
     * @return
     */
    public Driver[] getDriverList() {
        return driverList;
    }
    private String[] header;
    private Driver[] driverList;
}
